local mizhao = fk.CreateSkill {

  name = "joy__mizhao",

  tags = {  },

}



mizhao:addEffect("active", {
  name = "joy__mizhao",
  anim_type = "control",
  min_card_num = 1,
  target_num = 1,
  can_use = function(self, player)
    return not player:isKongcheng() and player:usedSkillTimes(mizhao.name, Player.HistoryPhase) == 0
  end,
  card_filter = function(self, player, to_select, selected)
    return Fk:currentRoom():getCardArea(to_select) ~= Card.PlayerEquip
  end,
  target_filter = function(self, player, to_select, selected)
    return #selected == 0 and to_select ~= player.id
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local target = effect.tos[1]
    local cards = effect.cards
    if player.dead or target.dead or target:isKongcheng() then return end
    room:moveCardTo(cards, Player.Hand, target, fk.ReasonGive, mizhao.name, nil, false)
    local targets = table.filter(room:getOtherPlayers(player), function(p)
      return target:canPindian(p)
    end)
    if #targets == 0 then return end
    local tos = room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, 1, "#mizhao-choose::"..target.id, mizhao.name, false)
    local to = room:getPlayerById(tos[1])
    local pindian = target:pindian({to}, mizhao.name)
    if pindian.results[to.id].winner then
      local winner, loser
      if pindian.results[to.id].winner == target then
        winner = target
        loser = to
      else
        winner = to
        loser = target
      end
      if loser.dead then return end
      room:useVirtualCard("slash", nil, winner, {loser}, mizhao.name)
    end
  end
})

return mizhao